﻿using System;
using System.Collections.Generic;
using System.Text;

namespace YmSoft.Kblog.Utility
{
    /// <summary>
    /// HTML转换相关类
    /// </summary>
    public class HtmlOperate
    {
        public HtmlOperate()
        {

        }
        /// <summary>
        /// HTML转换成文本格式
        /// </summary>
        /// <returns></returns>
        public string HtmlConvertText(string htmlencode)
        {
            htmlencode = htmlencode.Replace(" ", "&nbsp;");
            htmlencode = htmlencode.Replace("<", "&lt;");
            htmlencode = htmlencode.Replace(">", "&gt;");
            //htmlencode = htmlencode.Replace("&", "&amp;");
            htmlencode = htmlencode.Replace("\"", "&quot;");
            return htmlencode;
        }
        /// <summary>
        /// 文本转换成HTML格式
        /// </summary>
        /// <param name="textencode"></param>
        /// <returns></returns>
        public string TextConvertHtml(string textencode)
        {
            textencode = textencode.Replace("&nbsp;", " ");
            textencode = textencode.Replace("&lt;", "<");
            textencode = textencode.Replace("&gt;", ">");
            //textencode = textencode.Replace("&amp;", "&");
            textencode = textencode.Replace("&quot;", "\"");
            return textencode;
        }
    }
}
